<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改基础设置')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-baseconfig-edit" th:object="${ylyxBaseconfig}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">赠送倍数：</label>
                <div class="col-sm-8">
                    <input name="rechargeSend" th:field="*{rechargeSend}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">官方QQ群：</label>
                <div class="col-sm-8">
                    <input name="serviceQqgroup" th:field="*{serviceQqgroup}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客服QQ：</label>
                <div class="col-sm-8">
                    <input name="serviceQq" th:field="*{serviceQq}" class="form-control" type="text">
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">客服微信：</label>
                <div class="col-sm-8">
                    <input name="serviceWx" th:field="*{serviceWx}" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">客服微信二维码：</label>
                <div class="col-sm-8">
                    <input id="wxPictureUrl" type="hidden" name="wxPicture" th:field="*{wxPicture}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="wxPicture" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客服邮箱：</label>
                <div class="col-sm-8">
                    <input name="serviceEmail" th:field="*{serviceEmail}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系人：</label>
                <div class="col-sm-8">
                    <input name="relatePerson" th:field="*{relatePerson}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="relatePhone" th:field="*{relatePhone}" class="form-control" type="text">
                </div>
            </div>
        </form>
        <div>
            <button style="display:block;margin:0 auto" type="button" class="btn btn-success" onclick="saveSetting();">提交</button>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "ylyx/baseconfig";
        $("#form-baseconfig-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-baseconfig-edit').serialize());
            }
        }

        function saveSetting() {
            /*if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-tasksetting-edit').serialize());
            }*/
            debugger;
            var formData = new FormData();
            formData.append('id',$("#id").val());
            formData.append('rechargeSend',$("#rechargeSend").val());
            formData.append('serviceQq',$("#serviceQq").val());
            /*formData.append('serviceWx',$("#serviceWx").val());*/
            /*formData.append('freeVip',$("#freeVip").val());*/
            formData.append('serviceEmail',$("#serviceEmail").val());
            formData.append('serviceQqgroup',$("#serviceQqgroup").val());
            formData.append('wxPicture',$("#wxPictureUrl").val());
            formData.append('relatePerson',$("#relatePerson").val());
            formData.append('relatePhone',$("#relatePhone").val());
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': '/common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

    </script>
</body>
</html>